package com.pk.nds.home;

import java.net.URL;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;

import com.cs.pk.utils.Constants;

public class HomePageAction implements IWorkbenchWindowActionDelegate {

	private IWorkbenchWindow parent = null;

	public void dispose() {
		parent = null;
	}

	public void init(IWorkbenchWindow window) {
		parent = window;
	}

	public void run(IAction action) {
		try {
			IWebBrowser browser = parent.getWorkbench().getBrowserSupport()
					.createBrowser(IWorkbenchBrowserSupport.NAVIGATION_BAR,
							"NDSHome", "NDS",
							"NDS");
			String url = PlatformUI.getPreferenceStore().getString(
					Constants.HOMEURL) != null ? PlatformUI
							.getPreferenceStore().getString(Constants.HOMEURL)
							: PlatformUI.getPreferenceStore().getDefaultString(
									Constants.HOMEURL);
			if(!url.startsWith("http")) {
				url="http://"+url;
			}
			
			browser.openURL(new URL(url));
		} catch (Exception e) {
               e.printStackTrace();
		}
	}

	public void selectionChanged(IAction action, ISelection selection) {

	}

}
